package com.wenbo.wenbo.controller;

import cn.hutool.core.util.StrUtil;
import com.wenbo.wenbo.dto.StoryDto;
import com.wenbo.wenbo.service.StoryService;
import com.wenbo.wenbo.utils.ResultObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ywb
 * @date 2021年12月08日 9:57
 */
@RestController
@RequestMapping("/api/story")
public class StoryController {

    @Resource
    private StoryService storyService;


    @GetMapping("/getStory")
    public ResultObject<StoryDto> getStory(String name, String type) {
        if (StrUtil.isBlankIfStr(type)) {
            type = "3";
        }
        List<StoryDto> list = storyService.getStory(name, type);
        return ResultObject.ok("查询成功").setData(list);
    }

    @GetMapping("/getStoryInfo")
    public ResultObject<StoryDto> getStoryInfo(String id) {
        StoryDto info = storyService.getStoryInfo(id);
        return ResultObject.ok("查询成功").setData(info);
    }

    @GetMapping("/getStoryList")
    public ResultObject<Void> getStoryList() throws InterruptedException {
        storyService.getStoryList();
        return ResultObject.ok("查询成功");
    }

}
